var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

// 白亚楠模块
var baiRouter = require('./routes/bai');
// 赵琳辉模块
var zhaoRouter = require('./routes/zhao');
// 刘津芳模块
var liuRouter = require('./routes/liu');
// 王烨模块
var wangRouter = require('./routes/wang');
// 李雨恒模块
var liRouter = require('./routes/li');
// 秦亚凯模块
var qinRouter = require('./routes/qin');
// 候庆辉模块
var houRouter = require('./routes/hou');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// 白亚楠模块
app.use('/bai', baiRouter);
// 赵琳辉模块
app.use('/zhao', zhaoRouter);
// 刘津芳模块
app.use('/liu', liuRouter);
// 王烨模块
app.use('/wang', wangRouter);
// 李雨恒模块
app.use('/li', liRouter);
// 秦亚凯模块
app.use('/qin', qinRouter);
// 候庆辉模块
app.use('/hou', houRouter);

// catch 404 and forward to error handler
app.use(function (req, res, next) {
  next(createError(404));
});

// error handler
app.use(function (err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;
